import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:wallet_utils/report_widget/click_widget.dart';
import '../bean/feedbackType.dart';
import '../color.dart';
import '../text_style.dart';
typedef SubmitCallback = void Function(String id);
class IdentityDialog extends Dialog {
  SubmitCallback? submitCallback;
  final VoidCallback? noCallback;
  final VoidCallback? backCallback;
  final String? content;
  final String? title;
  final String? name;
  final String? yesStr;
  final String? noStr;
  final String? tail;
  List<FeedbackTypeBean> list=[];
  //是否包含输入框
  final bool? isEdit;
  final TextEditingController? controller;
  String? question='';
  IdentityDialog(
    this.content, {
    Key? key,
    this.submitCallback,
    this.noCallback,
    this.yesStr,
    this.noStr,
    this.name,
    this.tail,
    this.title,
    this.isEdit,
    this.controller,
    this.backCallback,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    list.add(FeedbackTypeBean('1小时后', ColorManager.colorFFFFFF, ColorManager.colorD93C3A,ColorManager.colorF6F6F6));
    list.add(FeedbackTypeBean('2小时后', ColorManager.colorF8F9FA, ColorManager.color333333,ColorManager.colorF6F6F6));
    list.add(FeedbackTypeBean('1天后', ColorManager.colorF8F9FA, ColorManager.color333333,ColorManager.colorF6F6F6));
    return Material(
      color: Colors.transparent,
      child: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Container(
              margin: EdgeInsets.only(left: 37.w, right: 37.w, bottom: 30.w),
              decoration: const BoxDecoration(
                image: DecorationImage(
                  image: AssetImage("assets/auth_id_alert.png"),
                  fit: BoxFit.cover,
                ),
              ),
              constraints: BoxConstraints(minHeight: 370.w),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: <Widget>[
                  Container(
                    margin: EdgeInsets.only(bottom: 10.w, top: 40.w, left: 25.w),
                    alignment: Alignment.centerLeft,
                    child: Text(
                      title ?? 'ocr日历提醒弹窗',
                      style: TextStyleUtils.style000000(fontSize: 20.sp, fontWeight: FontWeight.w500),
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.only(right: 80.w,left: 25.w,bottom: 20.w),
                      child: Text(
                    '身份证不在身边？您可以设置提醒稍后上传',
                    style: TextStyleUtils.style000000(fontSize: 14.sp),
                  )),
                  StatefulBuilder(
                    builder: (context,setState) {
                      return ListView.builder(
                        padding: EdgeInsets.zero,
                        shrinkWrap: true,
                        physics: const NeverScrollableScrollPhysics(),
                        itemCount: list.length,
                        itemBuilder: (BuildContext context, int index) {
                          return buildItem(index,setState);
                        },
                      );
                    }
                  ),
                  Visibility(
                    visible: false,
                    child: Container(
                      margin: EdgeInsets.symmetric(horizontal: 24.w),
                      child: RichText(
                        textAlign: TextAlign.center,
                        text: TextSpan(
                          children: [
                            TextSpan(
                              text: content,
                              style: TextStyleUtils.style000000(fontSize: 15.sp),
                            ),
                            TextSpan(text: name ?? '', style: TextStyleUtils.styleF65247(fontSize: 14.sp)),
                            TextSpan(
                              text: tail ?? '',
                              style: TextStyleUtils.style4d4d4d(fontSize: 14.sp),
                            ),
                          ],
                        ),
                      ),
                    ),
                  ),
                  Visibility(
                    visible: isEdit ?? false,
                    child: Container(
                      margin: EdgeInsets.symmetric(horizontal: 24.w),
                      height: 38.w,
                      decoration: BoxDecoration(
                        border: Border.all(color: ColorManager.colorF2F2F2, width: 1.w),
                        borderRadius: BorderRadius.all(Radius.circular(4.w)),
                      ),
                      alignment: Alignment.center,
                      child: TextField(
                        decoration: const InputDecoration(
                            border: OutlineInputBorder(
                              //保证TextField输入内容居中
                              borderSide: BorderSide(
                                color: Colors.transparent,
                              ),
                            ),
                            enabledBorder: OutlineInputBorder(
                              borderSide: BorderSide(
                                color: Colors.transparent,
                              ),
                            ),
                            disabledBorder: OutlineInputBorder(
                              borderSide: BorderSide(
                                color: Colors.transparent,
                              ),
                            ),
                            focusedBorder: OutlineInputBorder(
                              borderSide: BorderSide(
                                color: Colors.transparent,
                              ),
                            ),
                            contentPadding: EdgeInsets.zero),
                        controller: controller,
                        textAlign: TextAlign.center,
                        style: TextStyleUtils.style2A2A2A(),
                      ),
                    ),
                  ),
                  SizedBox(height: 24.w),
                  Container(
                    margin: EdgeInsets.symmetric(horizontal: 24.w),
                    child: InkWell(
                      onTap: () {
                        if(question!.isNotEmpty){
                          submitCallback!('question');
                        }
                      },
                      child: Container(
                        height: 40.w,
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                          color: ColorManager.colorD93C3A,
                          borderRadius: BorderRadius.all(Radius.circular(20.w)),
                        ),
                        child: Text(
                          yesStr ?? '确定',
                          style: TextStyleUtils.styleFFFFFF(
                            fontSize: 16.sp,
                          ),
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ),
            ClickWidget(
                onTap: () {
                  backCallback!();
                },
                child: Image.asset(
                  'images/auth_alert_close.png',
                  width: 20.w,
                  height: 20.w,
                ))
          ],
        ),
      ),
    );
  }

  Widget buildItem(int index,StateSetter setState) {
    return ClickWidget(
      onTap: (){
        setState(() {
          //更新选中状态
          feedbackCheck(index);
        });
      },
      child: Container(
        width: 210.w,
        height: 40.w,
        alignment: Alignment.center,
        margin: EdgeInsets.only(top: 10.w,left: 37.w,right: 37.w),
        decoration: BoxDecoration(
          color: ColorManager.colorF6F6F6,
          border: Border.all(width: 1, color: list[index].bordColor ?? ColorManager.colorF6F6F6),
          borderRadius: BorderRadius.all(Radius.circular(5.w)),
        ),
        child: Text(list[index].name ?? '',style: TextStyleUtils.style000000(fontSize: 16.sp),),
      ),
    );
  }

  void feedbackCheck(int index) {
    for (int i = 0; i < list.length; i++) {
      if (index == i) {
        question=list[i].name;
        list[i].nameColor = ColorManager.colorD93C3A;
        list[i].typeColor = ColorManager.colorFFFFFF;
        list[i].bordColor = ColorManager.colorD93C3A;
      } else {
        list[i].nameColor = ColorManager.color333333;
        list[i].typeColor = ColorManager.colorF8F9FA;
        list[i].bordColor = ColorManager.colorF8F9FA;
      }
    }

  }
}
